<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Import::Into - Import packages into other packages - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Import-Into - MetaCPAN" href="https://metacpan.org/dist/Import-Into/releases.rss" />
        <link rel="canonical" href="./Import::Into.html" />
        <meta name="description" content="Import packages into other packages" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Import::Into" />
<meta name="twitter:title"       content="Import::Into" />
<meta name="twitter:description" content="Import packages into other packages" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Import::Into.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Import-Into was released.">
      <span class="relatize">28 Aug 2015 00:30:22 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Import-Into">Import-Into</a>
  </li>
  <li>
    Module version: 1.002005
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Import-Into/source/lib/Import/Into.pm">Source</a>
    (<a href="https://metacpan.org/dist/Import-Into/source/lib/Import/Into.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Import-Into/source/lib/Import">Browse</a>
    (<a href="https://metacpan.org/dist/Import-Into/source/lib/Import?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Import-Into/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Import-Into/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/Import-Into.git">Repository</a>
          (<a rel="noopener nofollow" href="git://git.shadowcat.co.uk/p5sagit/Import-Into.git">git clone</a>)
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Import-Into">Issues</a>
      (1)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Import-Into+1.002005" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/I/Import-Into.html?oncpan=1&amp;distmat=1&amp;version=1.002005&amp;grade=2" style="color: #090">1437</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/I/Import-Into.html?oncpan=1&amp;distmat=1&amp;version=1.002005&amp;grade=3" style="color: #900">2</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/I/Import-Into.html?oncpan=1&amp;distmat=1&amp;version=1.002005&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/HAARG/Import-Into-1.002005">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Import-Into who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 6
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Import-Into-1.002005/index.html">79.66% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.6.0
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Import-Into/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/H/HA/HAARG/Import-Into-1.002005.tar.gz">
      Download (<span itemprop="fileSize">7.57KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FHAARG%2FImport-Into-1.002005%2Flib%2FImport%2FInto.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Import-Into/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Import-Into/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Import-Into">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Import-Into">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Import/Into.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="HAARG/Import-Into-1.002005"
>1.002005
  (HAARG on 2015-08-28)</option>
<option
  
  value="ETHER/Import-Into-1.002004"
>1.002004
  (ETHER on 2014-07-09)</option>
<option
  
  value="HAARG/Import-Into-1.002001"
>1.002001
  (HAARG on 2014-03-04)</option>
<option
  
  value="HAARG/Import-Into-1.002000"
>1.002000
  (HAARG on 2013-12-10)</option>
<option
  
  value="MSTROUT/Import-Into-1.001000"
>1.001000
  (MSTROUT on 2012-05-12)</option>
<option
  
  value="MSTROUT/Import-Into-1.000003"
>1.000003
  (MSTROUT on 2012-05-06)</option>
<option
  
  value="MSTROUT/Import-Into-1.000002"
>1.000002
  (MSTROUT on 2012-05-05)</option>
<optgroup label="BackPAN">'
<option
  
  value="ETHER/Import-Into-1.002003"
>1.002003
  (ETHER on 2014-07-09)</option>
<option
  
  value="ETHER/Import-Into-1.002002"
>1.002002
  (ETHER on 2014-05-06)</option>
<option
  
  value="ETHER/Import-Into-1.001001"
>1.001001
  (ETHER on 2013-03-26)</option>
<option
  
  value="MSTROUT/Import-Into-1.000001"
>1.000001
  (MSTROUT on 2012-05-03)</option>
<option
  
  value="MSTROUT/Import-Into-1.000000"
>1.000000
  (MSTROUT on 2012-05-03)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/HAARG/Import-Into-1.002005/diff/' + encodeURIComponent(this.value) + '/lib/Import/Into.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="HAARG/Import-Into-1.002005"
>1.002005
  (HAARG on 2015-08-28)</option>
<option
  
  value="ETHER/Import-Into-1.002004"
>1.002004
  (ETHER on 2014-07-09)</option>
<option
  
  value="HAARG/Import-Into-1.002001"
>1.002001
  (HAARG on 2014-03-04)</option>
<option
  
  value="HAARG/Import-Into-1.002000"
>1.002000
  (HAARG on 2013-12-10)</option>
<option
  
  value="MSTROUT/Import-Into-1.001000"
>1.001000
  (MSTROUT on 2012-05-12)</option>
<option
  
  value="MSTROUT/Import-Into-1.000003"
>1.000003
  (MSTROUT on 2012-05-06)</option>
<option
  
  value="MSTROUT/Import-Into-1.000002"
>1.000002
  (MSTROUT on 2012-05-05)</option>
<optgroup label="BackPAN">'
<option
  
  value="ETHER/Import-Into-1.002003"
>1.002003
  (ETHER on 2014-07-09)</option>
<option
  
  value="ETHER/Import-Into-1.002002"
>1.002002
  (ETHER on 2014-05-06)</option>
<option
  
  value="ETHER/Import-Into-1.001001"
>1.001001
  (ETHER on 2013-03-26)</option>
<option
  
  value="MSTROUT/Import-Into-1.000001"
>1.000001
  (MSTROUT on 2012-05-03)</option>
<option
  
  value="MSTROUT/Import-Into-1.000000"
>1.000000
  (MSTROUT on 2012-05-03)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="./Module::Runtime.html" title="Module::Runtime" class="ellipsis">Module::Runtime</a></li>
  <li><a href="https://metacpan.org/pod/strict" title="strict" class="ellipsis">strict</a></li>
  <li><a href="https://metacpan.org/pod/warnings" title="warnings" class="ellipsis">warnings</a></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Import::Into/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Import%3A%3AInto">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Import-Into">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/HAARG/Import-Into-1.002005/view/lib/Import/Into.pm">This version</a>
    </li>
    <li>
      <a href="./Import::Into.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/MELO"><img src="https://www.gravatar.com/avatar/4809188f41ad2613f4c240b72d97604c?d=identicon&amp;s=20" title="MELO" alt="MELO"></a>
<a class="display-all" href="https://metacpan.org/author/DRAEGTUN"><img src="https://www.gravatar.com/avatar/6f1ae19bf6507a7bd1ea0d0f6abfeb01?d=identicon&amp;s=20" title="DRAEGTUN" alt="DRAEGTUN"></a>
<a class="display-all" href="https://metacpan.org/author/SKAUFMAN"><img src="https://www.gravatar.com/avatar/2caf2787e235f58a65576632f93ef6c3?d=identicon&amp;s=20" title="SKAUFMAN" alt="SKAUFMAN"></a>
<a class="display-all" href="https://metacpan.org/author/KEEDI"><img src="https://www.gravatar.com/avatar/95f905a7a4ccc573c711e9d264c0fde8?d=identicon&amp;s=20" title="KEEDI" alt="KEEDI"></a>
<a class="display-all" href="https://metacpan.org/author/MJEMMESON"><img src="https://www.gravatar.com/avatar/e17c4cf81cbd75b5043884252c378c47?d=identicon&amp;s=20" title="MJEMMESON" alt="MJEMMESON"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Import-Into/plussers">21 PAUSE users</a>
</div>
<div>
    17 non-PAUSE users
</div>
</div>
    </li>
    <li>
<div id="metacpan_contributors">
  <div>
    <button class="btn-link"
      onclick="$(this).hide(); $('#metacpan_contributors ul').slideDown(); return false;"
    >and 1 contributors</button>
  </div>
  <ul style="display: none">
    <li class="contributor"
      data-contrib-email="mst@shadowcat.co.uk"
    >
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" />
      mst - Matt S. Trout (cpan:MSTROUT)
    </li>
  </ul>
</div>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/HAARG" class="author-name">Graham Knop</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Import/Into.pm&#39;" class="">
<option
  selected
  value="HAARG/Import-Into-1.002005"
>1.002005
  (HAARG on 2015-08-28)</option>
<option
  
  value="ETHER/Import-Into-1.002004"
>1.002004
  (ETHER on 2014-07-09)</option>
<option
  
  value="HAARG/Import-Into-1.002001"
>1.002001
  (HAARG on 2014-03-04)</option>
<option
  
  value="HAARG/Import-Into-1.002000"
>1.002000
  (HAARG on 2013-12-10)</option>
<option
  
  value="MSTROUT/Import-Into-1.001000"
>1.001000
  (MSTROUT on 2012-05-12)</option>
<option
  
  value="MSTROUT/Import-Into-1.000003"
>1.000003
  (MSTROUT on 2012-05-06)</option>
<option
  
  value="MSTROUT/Import-Into-1.000002"
>1.000002
  (MSTROUT on 2012-05-05)</option>
<optgroup label="BackPAN">'
<option
  
  value="ETHER/Import-Into-1.002003"
>1.002003
  (ETHER on 2014-07-09)</option>
<option
  
  value="ETHER/Import-Into-1.002002"
>1.002002
  (ETHER on 2014-05-06)</option>
<option
  
  value="ETHER/Import-Into-1.001001"
>1.001001
  (ETHER on 2013-03-26)</option>
<option
  
  value="MSTROUT/Import-Into-1.000001"
>1.000001
  (MSTROUT on 2012-05-03)</option>
<option
  
  value="MSTROUT/Import-Into-1.000000"
>1.000000
  (MSTROUT on 2012-05-03)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Import-Into">Import-Into-1.002005</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage three &#10;
          • 134 direct dependents &#10;          • 805 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Import-Into-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Import-Into-1.002005">
    <input type="hidden" name="author" value="HAARG">
    <input type="hidden" name="distribution" value="Import-Into">
    <button type="submit" class="favorite highlight"><span>38</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Import::Into.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>38</span> ++</a>
</div>
   / <span>Import::Into</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Import::Into.html#NAME">NAME</a></li>
  <li><a href="./Import::Into.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Import::Into.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Import::Into.html#METHODS">METHODS</a>
    <ul>
      <li><a href="./Import::Into.html#$package-%3Eimport::into(-$target,-@arguments-);">$package-&gt;import::into( $target, @arguments );</a></li>
      <li><a href="./Import::Into.html#$package-%3Eunimport::out_of(-$target,-@arguments-);">$package-&gt;unimport::out_of( $target, @arguments );</a></li>
    </ul>
  </li>
  <li><a href="./Import::Into.html#WHY-USE-THIS-MODULE">WHY USE THIS MODULE</a></li>
  <li><a href="./Import::Into.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Import::Into.html#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</a></li>
  <li><a href="./Import::Into.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Import::Into.html#CONTRIBUTORS">CONTRIBUTORS</a></li>
  <li><a href="./Import::Into.html#COPYRIGHT">COPYRIGHT</a></li>
  <li><a href="./Import::Into.html#LICENSE">LICENSE</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Import::Into - Import packages into other packages</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>  package My::MultiExporter;

  use Import::Into;

  # simple
  sub import {
    Thing1-&gt;import::into(scalar caller);
  }

  # multiple
  sub import {
    my $target = caller;
    Thing1-&gt;import::into($target);
    Thing2-&gt;import::into($target, qw(import arguments));
  }

  # by level
  sub import {
    Thing1-&gt;import::into(1);
  }

  # with exporter
  use base qw(Exporter);
  sub import {
    shift-&gt;export_to_level(1);
    Thing1-&gt;import::into(1);
  }

  # no My::MultiExporter == no Thing1
  sub unimport {
    Thing1-&gt;unimport::out_of(scalar caller);
  }</code></pre>

<p>People wanting to re-export your module should also be using <a href="./Import::Into.html">Import::Into</a>. Any exporter or pragma will work seamlessly.</p>

<p>Note: You do <b>not</b> need to make any changes to Thing1 to be able to call <code>import::into</code> on it. This is a global method, and is callable on any package (and in fact on any object as well, although it&#39;s rarer that you&#39;d want to do that).</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>Writing exporters is a pain. Some use <a href="https://metacpan.org/pod/Exporter">Exporter</a>, some use <a href="https://metacpan.org/pod/Sub::Exporter">Sub::Exporter</a>, some use <a href="https://metacpan.org/pod/Moose::Exporter">Moose::Exporter</a>, some use <a href="https://metacpan.org/pod/Exporter::Declare">Exporter::Declare</a> ... and some things are pragmas.</p>

<p>Exporting on someone else&#39;s behalf is harder. The exporters don&#39;t provide a consistent API for this, and pragmas need to have their import method called directly, since they effect the current unit of compilation.</p>

<p><code>Import::Into</code> provides global methods to make this painless.</p>

<h1 id="METHODS">METHODS</h1>

<h2 id="$package-&gt;import::into(-$target,-@arguments-);"><a id="package--import::into---target---arguments"></a>$package-&gt;import::into( $target, @arguments );</h2>

<p>A global method, callable on any package. Loads and imports the given package into <code>$target</code>. <code>@arguments</code> are passed along to the package&#39;s import method.</p>

<p><code>$target</code> can be an package name to export to, an integer for the caller level to export to, or a hashref with the following options:</p>

<dl>

<dt id="package">package</dt>
<dd>

<p>The target package to export to.</p>

</dd>
<dt id="filename">filename</dt>
<dd>

<p>The apparent filename to export to. Some exporting modules, such as <a href="https://metacpan.org/pod/autodie">autodie</a> or <a href="strictures.html">strictures</a>, care about the filename they are being imported to.</p>

</dd>
<dt id="line">line</dt>
<dd>

<p>The apparent line number to export to. To be combined with the <code>filename</code> option.</p>

</dd>
<dt id="level">level</dt>
<dd>

<p>The caller level to export to. This will automatically populate the <code>package</code>, <code>filename</code>, and <code>line</code> options, making it the easiest most constent option.</p>

</dd>
<dt id="version">version</dt>
<dd>

<p>A version number to check for the module. The equivalent of specifying the version number on a <code>use</code> line.</p>

</dd>
</dl>

<h2 id="$package-&gt;unimport::out_of(-$target,-@arguments-);"><a id="package--unimport::out_of---target---arguments"></a>$package-&gt;unimport::out_of( $target, @arguments );</h2>

<p>Equivalent to <code>import::into</code>, but dispatches to <code>$package</code>&#39;s <code>unimport</code> method instead of <code>import</code>.</p>

<h1 id="WHY-USE-THIS-MODULE"><a id="WHY"></a>WHY USE THIS MODULE</h1>

<p>The APIs for exporting modules aren&#39;t consistent. <a href="https://metacpan.org/pod/Exporter">Exporter</a> subclasses provide export_to_level, but if they overrode their import method all bets are off. <a href="https://metacpan.org/pod/Sub::Exporter">Sub::Exporter</a> provides an into parameter but figuring out something used it isn&#39;t trivial. Pragmas need to have their <code>import</code> method called directly since they affect the current unit of compilation.</p>

<p>It&#39;s ... annoying.</p>

<p>However, there is an approach that actually works for all of these types.</p>

<pre><code>  eval &quot;package $target; use $thing;&quot;</code></pre>

<p>will work for anything checking caller, which is everything except pragmas. But it doesn&#39;t work for pragmas - pragmas need:</p>

<pre><code>  $thing-&gt;import;</code></pre>

<p>because they&#39;re designed to affect the code currently being compiled - so within an eval, that&#39;s the scope of the eval itself, not the module that just <code>use</code>d you - so</p>

<pre><code>  sub import {
    eval &quot;use strict;&quot;
  }</code></pre>

<p>doesn&#39;t do what you wanted, but</p>

<pre><code>  sub import {
    strict-&gt;import;
  }</code></pre>

<p>will apply <a href="https://metacpan.org/pod/strict">strict</a> to the calling file correctly.</p>

<p>Of course, now you have two new problems - first, that you still need to know if something&#39;s a pragma, and second that you can&#39;t use either of these approaches alone on something like <a href="Moose.html">Moose</a> or <a href="Moo.html">Moo</a> that&#39;s both an exporter and a pragma.</p>

<p>So, a solution for that is:</p>

<pre><code>  use Module::Runtime;
  my $sub = eval &quot;package $target; sub { use_module(shift)-&gt;import(\@_) }&quot;;
  $sub-&gt;($thing, @import_args);</code></pre>

<p>which means that import is called from the right place for pragmas to take effect, and from the right package for caller checking to work - and so behaves correctly for all types of exporter, for pragmas, and for hybrids.</p>

<p>Additionally, some import routines check the filename they are being imported to. This can be dealt with by generating a <a href="https://metacpan.org/pod/perlsyn#Plain-Old-Comments-(Not!)">#line directive</a> in the eval, which will change what <code>caller</code> reports for the filename when called in the importer. The filename and line number to use in the directive then need to be fetched using <code>caller</code>:</p>

<pre><code>  my ($target, $file, $line) = caller(1);
  my $sub = eval qq{
    package $target;
  #line $line &quot;$file&quot;
    sub { use_module(shift)-&gt;import(\@_) }
  };
  $sub-&gt;($thing, @import_args);</code></pre>

<p>And you need to switch between these implementations depending on if you are targeting a specific package, or something in your call stack.</p>

<p>Remembering all this, however, is excessively irritating. So I wrote a module so I didn&#39;t have to anymore. Loading <a href="./Import::Into.html">Import::Into</a> creates a global method <code>import::into</code> which you can call on any package to import it into another package. So now you can simply write:</p>

<pre><code>  use Import::Into;

  $thing-&gt;import::into($target, @import_args);</code></pre>

<p>This works because of how perl resolves method calls - a call to a simple method name is resolved against the package of the class or object, so</p>

<pre><code>  $thing-&gt;method_name(@args);</code></pre>

<p>is roughly equivalent to:</p>

<pre><code>  my $code_ref = $thing-&gt;can(&#39;method_name&#39;);
  $code_ref-&gt;($thing, @args);</code></pre>

<p>while if a <code>::</code> is found, the lookup is made relative to the package name (i.e. everything before the last <code>::</code>) so</p>

<pre><code>  $thing-&gt;Package::Name::method_name(@args);</code></pre>

<p>is roughly equivalent to:</p>

<pre><code>  my $code_ref = Package::Name-&gt;can(&#39;method_name&#39;);
  $code_ref-&gt;($thing, @args);</code></pre>

<p>So since <a href="./Import::Into.html">Import::Into</a> defines a method <code>into</code> in package <code>import</code> the syntax reliably calls that.</p>

<p>For more craziness of this order, have a look at the article I wrote at <a href="http://shadow.cat/blog/matt-s-trout/madness-with-methods">http://shadow.cat/blog/matt-s-trout/madness-with-methods</a> which covers coderef abuse and the <code>${\...}</code> syntax.</p>

<p>And that&#39;s it.</p>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<p>I gave a lightning talk on this module (and <a href="https://metacpan.org/pod/curry">curry</a> and <a href="https://metacpan.org/pod/Safe::Isa">Safe::Isa</a>) at <a href="https://www.youtube.com/watch?v=wFXWV2yY7gE&amp;t=46m05s">YAPC::NA 2013</a>.</p>

<h1 id="ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</h1>

<p>Thanks to Getty for asking &quot;how can I get <code>use strict; use warnings;</code> turned on for all consumers of my code?&quot; and then &quot;why is this not a module?!&quot;.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>mst - Matt S. Trout (cpan:MSTROUT) &lt;mst@shadowcat.co.uk&gt;</p>

<h1 id="CONTRIBUTORS">CONTRIBUTORS</h1>

<p>haarg - Graham Knop (cpan:HAARG) &lt;haarg@haarg.org&gt;</p>

<p>Mithaldu - Christian Walde (cpan:MITHALDU) &lt;walde.christian@gmail.com&gt;</p>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright (c) 2012 the Import::Into <a href="./Import::Into.html#AUTHOR">&quot;AUTHOR&quot;</a> and <a href="./Import::Into.html#CONTRIBUTORS">&quot;CONTRIBUTORS&quot;</a> as listed above.</p>

<h1 id="LICENSE">LICENSE</h1>

<p>This library is free software and may be distributed under the same terms as perl itself.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Import::Into, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Import::Into</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Import::Into</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Import::Into.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
